/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilities;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author andrew
 */



public class ReadSmtp{
    
    private String smtp_address;
    private String smtp_port;
    private String auth;
    private String auth_username;
    private String auth_password;

    public ReadSmtp(HttpServletRequest request) {
        
        BufferedReader br = null;
        
        try {
            String sCurrentLine;
            br = new BufferedReader(new FileReader(request.getServletContext().getRealPath("/")+"config_smtp.txt"));
            
            String tmp;
            
            while ((sCurrentLine = br.readLine()) != null) {
                tmp = sCurrentLine.substring(0,sCurrentLine.lastIndexOf("="));
                if(tmp.equals("smtp_address")){
                    this.smtp_address = sCurrentLine.substring(sCurrentLine.lastIndexOf("=")+1);
                }else if(tmp.equals("smtp_port")){
                    this.smtp_port = sCurrentLine.substring(sCurrentLine.lastIndexOf("=")+1);
                }else if(tmp.equals("auth")){
                    this.auth = sCurrentLine.substring(sCurrentLine.lastIndexOf("=")+1);
                }else if(tmp.equals("auth_username")){
                    this.auth_username = sCurrentLine.substring(sCurrentLine.lastIndexOf("=")+1);
                }else if(tmp.equals("auth_password")){
                    this.auth_password = sCurrentLine.substring(sCurrentLine.lastIndexOf("=")+1);
                }
                
                //System.out.println("FILE-> "+sCurrentLine.substring(sCurrentLine.lastIndexOf("=")+1));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        
    }
    
    
    public String getSmtp_address() {
        return smtp_address;
    }

    public String getSmtp_port() {
        return smtp_port;
    }

    public String getAuth() {
        return auth;
    }

    public String getAuth_username() {
        return auth_username;
    }

    public String getAuth_password() {
        return auth_password;
    }

    
}
